#include<iostream>
#include<vector>
#include<string>
#include<map>
using namespace std;
vector<int> findSubstring(string s, vector<string>& words) {
    vector<int> v;
    map<string, int> hash2;
    for (auto ch : words) {
        hash2[ch]++;
    }
    int size1 = s.size(), size2 = words[0].size(), lens = words.size();
    for (int x = 0; x < lens; x++) {
        map<string, int> hash1;
        for (int left = x, right = x, count = 0; right + size2 <= size1;
            right += size2) {
            string in(s.begin() + right, s.begin() + right + size2);
            ++hash1[in];
            if (hash2.count(in) && hash1[in] <= hash2[in])
                count++;
            if (right - left + size2 == size2 * lens) {
                string out(s.begin() + left, s.begin() + left + size2);
                if (count == lens)
                    v.push_back(left);
                if (hash2.count(out) && hash1[out] <= hash2[out])
                    count--;
                hash1[out]--;
                left += size2;
            }
        }
    }
    return v;
}
int main()
{
    vector<string> _v{ "a", "a" };
    vector<int> v = findSubstring("aaa", _v);
    return 0;
}
